home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 6 code / TCP / NewsWatcher / NW Source / Shared Code / Reusable Source / iconutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-05  |  1.6 KB  |  70 lines  |  [TEXT/MMCC]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     iconutil.c
  4.  
  5.     This reusable module contains miscellaneous utility routines for working
  6.     with icons.
  7.     
  8.     Copyright © 1994-1995, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <Icons.h>
  13.  
  14. #include "def.h"
  15. #include "iconutil.h"
  16.  
  17.  
  18.  
  19. /*----------------------------------------------------------------------------
  20.     TrackIconClick 
  21.     
  22.     Track a click on an icon control.
  23.             
  24.     Entry:    where = location of mouse down in local coords.
  25.             iconRect = pointer to icon rectangle.
  26.             hotRect = pointer to "hot" rectangle, or nil to use
  27.                 icon mask.
  28.             iconID = resource ID of icon.
  29.             
  30.     Exit:    function result = true if icon clicked.
  31. ----------------------------------------------------------------------------*/
  32.  
  33. Boolean TrackIconClick (Point where, Rect *iconRect, Rect *hotRect, 
  34.     short iconID)
  35. {
  36.     Boolean iconDrawnSelected = false;
  37.     Boolean hot = true;
  38.     
  39.     if (hotRect == nil) {
  40.         if (!PtInIconID(where, iconRect, 0, iconID)) return false;
  41.     } else {
  42.         if (!PtInRect(where, hotRect)) return false;
  43.     }
  44.     do {
  45.         if (hot) {
  46.             if (!iconDrawnSelected) {
  47.                 PlotIconID(iconRect, 0, ttSelected, iconID);
  48.                 iconDrawnSelected = true;
  49.             }
  50.         } else {
  51.             if (iconDrawnSelected) {
  52.                 PlotIconID(iconRect, 0, ttNone, iconID);
  53.                 iconDrawnSelected = false;
  54.             }
  55.         }
  56.         GetMouse(&where);
  57.         if (hotRect == nil) {
  58.             hot = PtInIconID(where, iconRect, 0, iconID);
  59.         } else {
  60.             hot = PtInRect(where, hotRect);
  61.         }
  62.     } while (StillDown());
  63.     if (iconDrawnSelected) {
  64.         PlotIconID(iconRect, 0, ttNone, iconID);
  65.         return true;
  66.     } else {
  67.         return false;
  68.     }
  69. }
  70.